<template>
    <div>
        <el-table
                class="table"
                style="margin-top: 3%"
                :data="creditinfoList"
                width="100%"
                border>
            <el-table-column
                    prop="creditNo"
                    label="债权编号"
                    width="100px">
            </el-table-column>
            <el-table-column
                    prop="time"
                    width="100px"
                    label="申报时间">
            </el-table-column>
            <el-table-column
                    prop="stateStr"
                    label="状态">
            </el-table-column>
            <el-table-column
                    label="操作"
                    width="50px">
                <template slot-scope="scope">
                    <el-button @click="toChange(scope.row)" type="text" size="small">查看</el-button>
                </template>
            </el-table-column>
        </el-table>

        <el-button type="primary" style="width: 100%" @click="toCredit">新增我的债权</el-button>

        <!--<el-dialog
                title="请选择债权人"
                :visible.sync="chosenCreditorVisible"
                width="95%"
                center>
            <el-form :model="form">
                <el-form-item label="请选择申请债权人" :label-width="creditorLabelWidth">
                    <el-select v-model="form.creditor" placeholder="债权人">
                        <div v-for="creditor in creditorList">
                            <el-option :label="creditor.name" :value="creditor.id"></el-option>
                        </div>
                        &lt;!&ndash;<el-option label="其他" :value="-1"></el-option>&ndash;&gt;
                    </el-select>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="chosenCreditorVisible = false">取 消</el-button>
                <el-button type="primary" @click="chosenCreditor">确 定</el-button>
            </span>
        </el-dialog>-->

<!--
        <el-dialog title="" :visible.sync="registerVisible" width="95%" center>
            <el-form ref="form" :model="form" :label-width="formLabelWidth">
                <el-form-item label="债权类型: ">
                    <el-select v-model="form.creditType" placeholder="请选择">
                        <el-option
                                v-for="nature in creditType"
                                :key="nature.value"
                                :label="nature.value"
                                :value="nature.value"
                                :item="nature.value">
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="债权性质: ">
                    <el-select v-model="form.creditNature" placeholder="请选择">
                        <el-option
                                v-for="nature in creditNature"
                                :key="nature.value"
                                :label="nature.value"
                                :value="nature.value"
                                :item="nature.value">
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="是否放弃优先受偿: ">
                    <el-radio-group v-model="form.giveFirst">
                        <el-radio label="是"></el-radio>
                        <el-radio label="否" style="margin-left: 20px"></el-radio>
                    </el-radio-group>
                </el-form-item>

                <el-form-item label="担保形式: ">
                    <el-select v-model="form.guaranteeForm" placeholder="请选择">
                        <el-option
                                v-for="state in guaranteeForm"
                                :key="state.value"
                                :label="state.value"
                                :value="state.value">
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="registerVisible = false">取消</el-button>
                <el-button @click="toRegister" type="primary">确定</el-button>
                 <el-button @click="toRegister" type="primary">更多</el-button>
            </span>
        </el-dialog>-->

    </div>
</template>

<script>
    import util from 'assets/js/util.js'

    export default {
        data() {
            return {
                createDate: '',
                creditNo: '',
                stateStr: '',
                creditorList: [],
                chosenCreditorVisible: false,
                registerVisible: false,
                formLabelWidth: '150px',
                creditorLabelWidth: '130px',
                routerName: '',
                form: {
                    giveFirst: '否',
                    creditType: '金融借贷',
                    guaranteeForm: '抵押',
                    creditNature: '职工债权'
                },
                creditNature: [
                    {
                        value: '职工债权'
                    }, {
                        value: '普通债权'
                    }, {
                        value: '税收债权'
                    },{
                        value: '优先债权'
                    }
                ],
                guaranteeForm: [
                    {
                        value: '抵押'
                    }, {
                        value: '质押'
                    }, {
                        value: '其他'
                    }
                ],
                creditType: [
                    {
                        value: '金融借贷'
                    }, {
                        value: '民间借贷'
                    }, {
                        value: '货款'
                    },{
                        value: '其他'
                    }
                ],
            }
        },
        props: [
            'creditinfoList'
        ],
        mounted() {


           /* const _self = this;
            util.ajax({
                url: '/creditor/detail',
                params: {},
                success: function (data) {
                    data.data.forEach(_creditor => _self.creditorList.push({
                        orgName: _creditor.orgName,
                        name: _creditor.name,
                        id: _creditor.id,
                    }));
                }
            })*/
        },
        methods: {
            toCredit: function () {
                window.location.href = '../register/register-credit.html?'+ "&type=insert";
            },
            toChange: function (row) {
                window.location.href = '../credit/credit.html?' + 'id=' + row.id;
            },
            addCredit: function () {
                //this.chosenCreditorVisible = true
                this.registerVisible = true
            },
            chosenCreditor: function () {
                if (this.form.creditor === '') {
                    alert('请选择债权人!!!');
                    return
                }
                this.chosenCreditorVisible = false;

                if (this.form.creditor === -1)
                    this.registerVisible = true;
                else
                    window.location.href = '../register/register-credit.html?' + 'caseId=' + this.caseId + '&creditorId=' + this.creditorId;
            },
            toRegister: function () {
                window.location.href = '../register/register.html?' + 'caseId=' + this.caseId + '&creditType='
                    + this.matchNature(this.form.creditType) + '&agentType=' + (this.form.agentType === '否' ? 0 : 1) + '&&attendState='
                    + this.matchAttendState(this.form.attendState);
            },
            matchAttendState: function (text) {
                let type = 0;
                switch (text) {
                    case '参加尚不确定':
                        type = 0;
                        break;
                    case '参加现场会议':
                        type = 1;
                        break;
                    case '参加网络会议':
                        type = 2;
                        break;
                    case '':
                        type = 3;
                        break;
                    default:
                        type = 0;
                        break;
                }
                return type
            },
            matchNature: function (text) {
                let type = 0;
                switch (text) {
                    case '个人':
                        type = 1;
                        break;
                    case '公司（机构）':
                        type = 2;
                        break;
                    case '行政机关（金融机构）':
                        type = 3;
                        break;
                    default:
                        break
                }
                return type
            },
            matchTypeText: function (type) {
                let typeText = '';
                switch (type) {
                    case 1:
                        typeText = '职工债权';
                        break;
                    case 2:
                        typeText = '普通债权';
                        break;
                    case 3:
                        typeText = '税收债权';
                        break;
                    case 4:
                        typeText = '优先债权';
                        break;
                    default:
                        break
                }
                return typeText
            },
            matchAttendStateText: function (type) {
                let typeText = '';
                switch (type) {
                    case 0:
                        typeText = '参加尚不确定';
                        break;
                    case 1:
                        typeText = '参加现场会议';
                        break;
                    case 2:
                        typeText = '参加网络会议';
                        break;
                    case 3:
                        typeText = '';
                        break;
                    default:
                        typeText = '参加尚不确定';
                        break;
                }
                return typeText
            },

            matchNatureText: function (type) {
                let text = 0;
                switch (type) {
                    case 1:
                        text = '个人';
                        break;
                    case 2:
                        text = '公司（机构）';
                        break;
                    case 3:
                        text = '行政机关（金融机构）';
                        break;
                    default:
                        break
                }
                return text;
            },
            /*
             creditDetail: function (row, column, cell, event) {
                 if (row.state === 11)
                     this.toChange(row);
                 else
                     this.toSure(row);
             },
            toDismissal: function (row) {
                window.location.href = '../credit/dismissal.html?' + 'caseId=' + this.caseId + '&&creditorId=' + this.creditorId + '&&creditId=' + row.id;
            },
            toSure: function (row) {
                window.location.href = '../credit/credit.html?' + 'caseId=' + this.caseId + '&&creditorId=' + this.creditorId + '&&creditId=' + row.id;
            },
            toQuery: function (row) {
                this.toSure(row);
            },*/
        },
    }
</script>
